package com.erbao.io.netty.refactor.transport;

import com.erbao.IoUtil;
import com.erbao.io.netty.refactor.rpc.protocol.MyContent;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.FullHttpResponse;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.concurrent.CompletableFuture;

/**
 * @author CaoBaoYin
 * @since 23/9/5 15:40
 */
public class MyHttpResponseHandler extends ChannelInboundHandlerAdapter {

    CompletableFuture<Object> completableFuture;
    public MyHttpResponseHandler(CompletableFuture<Object> completableFuture) {
        this.completableFuture = completableFuture;
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        FullHttpResponse response = (FullHttpResponse) msg;
        MyContent content = IoUtil.getContent(response.content());
        this.completableFuture.complete(content.getResponseObj());

        super.channelRead(ctx, msg);
    }
}
